package service;

import bean.Customer;

/**
 * @title: CustomerList
 * @Author: zugzwang
 * @description:
 * @version: 1.0.0
 * @CreateTime: 2022-07-20  12:22
 */
public class CustomerList {
    private Customer[] customers;
    private  int total;

    public CustomerList(int totalCustomer){
        customers = new Customer[totalCustomer];
    }
/**
 * @description:添加指定用户到数组中
 * @author: wzj
 * @date: 2022/7/20 12:28
 * @param: [customer]
 **/
    public boolean addCustomer(Customer customer){
        if(total>= customers.length)
            return false;
        customers[total++]=customer;
        return true;
    }
/**
 * @description:修改指定索引位置的客户信息
 * @author: wzj
 * @date: 2022/7/20 12:35
 * @param: [index, cust]
 **/
    public boolean replaceCustomer(int index,Customer cust){
        if(index<0||index>=total)
            return false;
        customers[index]=cust;
        return true;
    }
/**
 * @description:  删除指定索引位置的客户信息
 * @author: wzj
 * @date: 2022/7/20 12:39
 * @param: [index]
 **/
    public boolean deleteCustomer(int index){
        if(index<0||index>=total)
            return false;
        for(int i=index;i< customers.length;i++)
            customers[i]=customers[i+1];
        customers[--total]=null;
        return true;
    }
/**
 * @description: 获取所有客户信息
 * @author: wzj
 * @date: 2022/7/20 12:49
 * @param: []
 **/
    public Customer[] getAllCustomers(){
        Customer[] custs = new Customer[total];
        for(int i=0;i< total;i++){
            custs[i]=customers[i];
        }
        return custs;
    }
/**
 * @description: 获取指定索引位置上的客户
 * @author: wzj
 * @date: 2022/7/20 12:51
 * @param: [index]
 **/
    public Customer getCustomer(int index){
        if(index<0||index>=total)
            return null;
        return customers[index];
    }
/**
 * @description: 获取存储客户的数量
 * @author: wzj
 * @date: 2022/7/20 12:52
 * @param: []
 **/
    public int getTotal(){
        return total;
    }
}
